import Vue from 'vue'
import App from './App.vue'
import router from './router'
import NProgress from '../public/js/nprogress'
import '../public/css/nprogress.css'
Vue.config.productionTip = false;
Vue.prototype.$http=axios;

//顶部动画加载
NProgress.configure({
  easing: 'ease', // 动画方式
  speed: 600, // 递增进度条的速度
  showSpinner: false, // 是否显示加载ico
  trickleSpeed: 200, // 自动递增间隔
  minimum: 0.3 // 初始化时的最小百分比
})

//判断用户是否登录
router.beforeEach((to, from, next) => {
  //在路由开始之前开启加载
  NProgress.start(); 
  if (to.path === '/login') {
    next();
  } else {
    let token = sessionStorage.getItem('token');
    if (token === null || token === '') {
      next('/login');
    } else {
      next();
    }
  }
});
router.afterEach(() => {
  //路由加载完成之后关闭加载
  NProgress.done();
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
